<template>
  <div>
    <el-card>
      <el-form :inline="true" :model="searchForm">
        <el-form-item label="操作用户">
          <el-input v-model="searchForm.username" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getLogList">查询</el-button>
          <el-button @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="logList" style="width: 100%">
        <el-table-column prop="username" label="操作用户" />
        <el-table-column prop="operation" label="操作描述" />
        <el-table-column prop="operation_time" label="操作时间" />
        <el-table-column prop="status" label="操作状态" :formatter="formatStatus" />
        <el-table-column label="操作">
          <template #default="scope">
            <el-button type="danger" link size="small" @click="deleteLog(scope.row.log_id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
          v-model:current-page="pageNum"
          v-model:page-size="pageSize"
          :total="total"
          @current-change="getLogList"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const searchForm = ref({ username: '' })
const logList = ref([])
const pageNum = ref(1)
const pageSize = ref(10)
const total = ref(0)

function getLogList() {
  console.log('查询日志列表', searchForm.value)
}

function resetSearch() {
  searchForm.value.username = ''
  getLogList()
}

function formatStatus(row) {
  return row.status === 1 ? '成功' : '失败'
}

function deleteLog(logId) {
  console.log('删除日志', logId)
}
</script>
